/*#################################################

Dropdown Menu | v1.2
Max Felker | max@bigroomstudios.com

Creates a dropdown menu

<div id="dropdown" class="dropdown-container">

	<a> parent link </a>

	<div class="dropdown-sub-container" style="display:none;">

		<div class="dropdown-wrapper">

			<div id="dropdown-sub" class="dropdown-container">

				<a> sub parent link </a>

				<div class="dropdown-sub-container" style="display:none;">

					<div class="dropdown-wrapper">

						<a> sub link </a>

					</div>

				</div>

			</div>

		</div>

	</div>

</div>

<script type="text/javascript">

	new Dropdown({
		container: 'dropdown',
		submenu: new Dropdown({
				container: 'dropdown-sub',
		}),
	});

</script>

#################################################*/

var Dropdown = Class.create({

	initialize: function(config) {
		
		// class properties
	
		this.container = $(config.container);
		this.sub_container = $$('#'+config.container+' .dropdown-sub-container')[0];
		this.parent_item = $$('#'+config.container+' .dropdown-parent-item')[0];
		this.parent_menu = config.parent_menu;
		
		this.menu_open = false;

		// observes
		
		this.container.on('mouseenter',this.show_menu.bind(this));
		this.container.on('mouseleave',this.hide_menu.bind(this));
		
		// add to live
		
		live.dropdowns.set(this.container.id,this);
	
	},

	show_menu: function() {

		clearTimeout(this.menu_timeout);

		if(!this.menu_open){

			this.menu_timeout = setTimeout(function(){

				this.menu_open = true;
		        	Effect.SlideDown(this.sub_container, { duration: 0.2});

			}.bind(this),200);
               
		}
	},

	hide_menu: function() {

		clearTimeout(this.menu_timeout);

        	if(this.menu_open){

			this.menu_timeout = setTimeout(function(){

				this.menu_open = false;
				Effect.SlideUp(this.sub_container, { duration: 0.2});

			}.bind(this),200);
               
		 }

	}

});
